﻿namespace AgileBoard.Domain
{
    using System;
    using System.Collections.Generic;
    using System.Collections.ObjectModel;
    using Iesi.Collections.Generic;
    using SharpArch.Core.DomainModel;

    [Serializable]
    public class Iteration : Entity
    {
        private ISet<Label> _labels = new HashedSet<Label>();
        private ISet<Story> _stories = new HashedSet<Story>();

        /// <summary>
        /// Created Date
        /// </summary>
        public virtual DateTime CreateTime { get; set; }

        /// <summary>
        /// Created by
        /// </summary>
        public virtual string Creator { get; set; }

        /// <summary>
        /// Release ID
        /// </summary>
        public virtual Guid IterationID { get; set; }

        /// <summary>
        /// Project ID
        /// </summary>
        public virtual Guid ReleaseID { get; set; }

        /// <summary>
        /// Release name
        /// </summary>
        public virtual string Name { get; set; }

        /// <summary>
        /// Release period start date
        /// </summary>
        public virtual DateTime PeriodFrom { get; set; }

        /// <summary>
        /// Release period end date
        /// </summary>
        public virtual DateTime PeriodTo { get; set; }

        public virtual ReadOnlyCollection<Story> Stories
        {
            get { return new List<Story>(_stories).AsReadOnly(); }
        }

        public virtual ReadOnlyCollection<Label> Labels
        {
            get { return new List<Label>(_labels).AsReadOnly(); }
        }

        public virtual void AddStory(Story story)
        {
            story.IterationID = IterationID.ToString();
            _stories.Add(story);
        }

        public virtual void RemoveStory(Story n)
        {
        }

        public virtual void AddLabel(Label label)
        {
            label.IterationID = IterationID.ToString();
            _labels.Add(label);
        }

        public virtual void RemoveLabel(Label n)
        {
        }
    }
}